import numpy as np
from scipy.stats import chi2
def stgPrb(martix):
    count = np.zeros(256,dtype=int)
    for i in range(len(martix)):
        for j in range(len(martix[0])):
            count[martix[i][j]] += 1  # 统计各个灰度值的个数
    h2i = count[0:255:2]  # N(2i) 灰度值偶数的个数
    h2is = (h2i+count[1:256:2])/2  # N(2i')
    filter= (h2is!=0)  # N(2i')不为0即为true
    k = sum(filter)  # 统计true个数，即统计N(2i)和N(2i+1)祖成分数字对数量k
    idx = np.zeros(k,dtype=int)  # 生成一个一行k列，内容全为0的矩阵
    for i in range(127):
        if filter[i]==True:
            idx[sum(filter[1:i])]=i  # 记录true的下标
    r=sum(((h2i[idx]-h2is[idx])**2)/(h2is[idx]))
    p = 1-chi2.cdf(r,k-1)
    print("卡方分析的值：",p)
    return p